package com.zsgeek.wisdchain.qutu.GestureRecognition.UI;

import android.content.Intent;
import android.os.Bundle;


import com.zsgeek.wisdchain.qutu.BaseActivity;
import com.zsgeek.wisdchain.qutu.GestureRecognition.Weight.ChaosGestureView;
import com.zsgeek.wisdchain.qutu.view.MainActivity;
import com.zsgeek.wisdchain.qutu.R;
import com.zsgeek.wisdchain.qutu.base.event.PreferenceHelper;
import com.zsgeek.wisdchain.qutu.tools.ToastHelper;

import java.util.List;

import butterknife.BindView;

public class ClosePatternPswActivity extends BaseActivity implements ChaosGestureView.GestureCallBack {
    @BindView(R.id.gesture1)
    ChaosGestureView gestureView;
    private int gestureFlg = -1;    //gestureFlg 1  删除密码    2   修改密码    3   为认证成功

    @Override
    public int getLayoutId() {
        return R.layout.activity_close_pattern_psw;
    }

    @Override
    protected void initView() {
        gestureFlg = getIntent().getIntExtra("gestureFlg", -1);
        if (gestureFlg == 1) {
            setTitle(R.string.delete_gesture_password);
        } else if (gestureFlg == 2) {
            setTitle(R.string.modify_gesture_password);
        } else {
            setTitle(R.string.verify_gesture_password);
            mToolbar.setNavigationIcon(null);
        }
        gestureView.setGestureCallBack(this);
        gestureView.clearCacheLogin();
    }

    @Override
    protected void initDate(Bundle savedInstanceState) {

    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }

    @Override
    public void gestureVerifySuccessListener(int stateFlag, List<ChaosGestureView.GestureBean> data, boolean success) {
        if (success) {
            if (gestureFlg == 1) {               //删除密码
                PreferenceHelper.putGestureFlag(false);
                gestureView.clearCache();
                ToastHelper.showToast(R.string.clear_gesture_password_successfully);
                finish();
            } else if (gestureFlg == 2) {       //修改密码
                ToastHelper.showToast(R.string.verify_gesture_password_successfully_please_reset);
                Intent intent = new Intent(ClosePatternPswActivity.this, SettingPatternPswActivity.class);
                startActivity(intent);
                finish();
            } else if (gestureFlg == 3) {
                startActivity(new Intent(ClosePatternPswActivity.this, MainActivity.class));
                finish();
            }
        } else {
            ToastHelper.showToast(R.string.unknown_exception_please_quit_and_again);
        }
    }

    @Override
    public void onBackPressed() {
        if (gestureFlg == 3)
            ToastHelper.showToast(R.string.please_verify_gesture_password);
        else
            super.onBackPressed();
    }
}
